package com.dao;

import java.util.List;

import com.beans.MenuInfo;
import com.jdbc.DBUtil;

public class MenuDao {
		/**
		 * 根据父级ID查询所有的子菜单,如果一级菜单,则把每个菜单的子菜单列表也查出来
		 * @param parentId 父级id,如果是0,则表查示查询所有的一级菜单
		 * @param roleId 角色id
		 * @return 菜单列表
		 */
		public List<MenuInfo>getMenuList(int parentId,int roleId){
			String sql="select * from menuInfo where parentId=?  and id in (select menuId from roleMenu where roleId=? )";
			List<MenuInfo> menuList=DBUtil.getList(sql, MenuInfo.class, parentId,roleId);
			
			for(MenuInfo m: menuList) {
				if(m.getParentId()==0) {
					m.setSubMenuList( getMenuList( m.getId(),roleId));
					 
				}
			}
			return menuList;
		}
		public List<MenuInfo>getMenuList(int parentId){
			List<MenuInfo> menuList=DBUtil.getList("select * from menuInfo where parentId=?", MenuInfo.class, parentId);
			
			for(MenuInfo m: menuList) {
				if(m.getParentId()==0) {
					m.setSubMenuList( getMenuList( m.getId()));
				}
			}
			return menuList;
		}
	}

